package com.dongpl.jar2mvn;

import com.dongpl.jar2mvn.frame.MyFrame;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.awt.*;

@Component
public class SwingStarter {

    private final MyFrame myFrame;

    @Autowired
    public SwingStarter(MyFrame myFrame) {
        this.myFrame = myFrame;
    }

    @EventListener(ApplicationReadyEvent.class)
    public void showUI() { // 启动GUI
        if (!GraphicsEnvironment.isHeadless()) {
            SwingUtilities.invokeLater(() -> myFrame.setVisible(true));
        } else {
            System.out.println("当前为 headless 模式，无法显示 Swing 界面");
        }
    }
}
